package com.qfx.modules.common.handler;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * <h5>描述:全局异常处理类</h5>
 * 优先执行此异常处理类
 *  
 */
@ControllerAdvice
public class MyExceptionHandler {
	private static final Logger LOG = LoggerFactory.getLogger(MyExceptionHandler.class);
	
	@ExceptionHandler(value =Exception.class)
    public String exceptionHandler(HttpServletRequest request, Exception e){
		
		String requestUri = request.getAttribute("org.springframework.web.servlet.HandlerMapping.lookupPath").toString();
		
		LOG.error("请求[{}]发生[{}]异常", requestUri,e.getMessage(), e);
		
		// 返回错误信息,交给其他异常处理类处理
		return e.getMessage();
    }
}
